package com.handinfo.uimenu.window;


import java.io.DataInputStream;
import java.io.IOException;
import java.util.Calendar;
import java.util.TimeZone;
import java.util.Vector;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

import com.handinfo.engine.AbstractGameScreen;
import com.handinfo.engine.GameManager;
import com.handinfo.game.AbstractGameActor;
import com.handinfo.game.ActorBuffer;
import com.handinfo.game.ActorItem;
import com.handinfo.game.ActorNPC;
import com.handinfo.game.ActorRole;
import com.handinfo.game.ChatItem;
import com.handinfo.game.GameMacro;
import com.handinfo.game.GameScene;
import com.handinfo.game.LoadingScreen;
import com.handinfo.game.MailItem;
import com.handinfo.game.MenuFunction;
import com.handinfo.game.RoleCombatSkill;
import com.handinfo.game.UserScreen;
import com.handinfo.uimenu.UIAbstractWindow;
import com.handinfo.uimenu.UIListener;
import com.handinfo.uimenu.UIManager;
import com.handinfo.uimenu.UIPopmenu;
import com.handinfo.uimenu.UITools;
import com.handinfo.uimenu.UIWindowFactory;
import com.handinfo.util.Tools;
import com.test.touch.GameTouchManager;
import com.test.touch.TouchListener;
import com.test.touch.TouchRect;

public class UIMain extends UIAbstractWindow {
	/**
	 * 新手引导用
	 */
	private final int STATE_NORMAL = 0;
	private final int STATE_EQUIP = 1;
	private final int STATE_SET_SHORTCUT = 2;
	private final int STATE_LEARN_SKILL = 3;
	private final int STATE_TASK = 4;

	public static String ID_EQUIP;
	public static long ID_SET_SKILL;
	public static long ID_LEARN_SKILL;
	public static int POS_SET_SKILL;

	private String[] m_yindaos;
	private int W_YINDAO = 80;
	//
	private int TIME_CHAT;// 聊天的计时器
	private final int TIMEER_CHAT = 50;
	//
	private final int H_PRE = UITools.H_PRE;// 聊天一行显示高度
	private final int H_CHAT = H_PRE * 3;
	private final int H_SHORTCUT = UITools.H_PRE;// 聊天栏显示高度
	//
	private ActorRole m_role;

	private Image m_pad,m_fire;
	public UIMain(int id) {
		super(id);
		initResource();
		m_role = GameManager.getInstance().m_role;
		setBounds(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);

		try {
			m_pad = Image.createImage("/pad.png");
			m_fire = Image.createImage("/fire.png");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		// m_state =STATE_TASK;
		// m_yindaos = Tools.getStrArray("按右软键，打开系统菜单", W_YINDAO);
	}
	
	
	

	protected void registerTouch() {
		super.registerTouch();
		
		initTouchRect(main_normal);
	}
	protected void onTouchRect(int[][] rect,int touchid) {
		if (rect == main_normal) {
			switch(touchid) {
			case 0:
				GameTouchManager.keyPressedLSoft();
				break;
			case 10:
				GameTouchManager.keyPressedRSoft();
				break;
			case 1:
			case 2:
			case 3:
			case 4:
			case 5:
			case 6:
			case 7:
			case 8:
			case 9:
				GameTouchManager.keyPressedNum(touchid);
				break;
			case 15:
				GameTouchManager.keyPressedFire();
				break;
			case 11:
			case 12:
			case 13:
			case 14:
				GameTouchManager.keyPressedDir(touchid-11);
				break;
			}
		}
	}
	private int[][] main_normal = new int[][]{
		//下面栏
			{106,283,36,36},//左软键0
			{142,296,21,21},
			{163,296,21,21},
			{185,296,21,21},
			{207,296,21,21},
			{229,296,21,21},
			{251,296,21,21},
			{273,296,21,21},
			{295,296,21,21},
			{317,296,21,21},
			{339,283,36,36},//右软键 10
			
			//方面和fire
			{0,214,47,46},//左 
			{41,160,49,51},//上
			{85,214,47,46},//右
			{41,261,49,51},//下
			{400,220,60,60},//fire 15
	};
	

	/**
	 * 进入新手引导的装备背包 2012-3-9 上午09:45:00 venizeng
	 */
	public static final void gotoTeachEquip(String equipID) {
		Tools.debugPrintln("进入新手引导的装备背包 = " + equipID);
		UIMain main = (UIMain) UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_MAIN);
		if (main == null) {
			Tools.debugPrintln("无法进入新手引导的装备背包 = " + equipID);
			return;
		}
		ID_EQUIP = equipID;
		main.m_state = main.STATE_EQUIP;
		main.m_yindaos = Tools.getStrArray("按右下边\"系\"，打开系统菜单", main.W_YINDAO);
	}

	/**
	 * 进入新手引导的学习技能 2012-3-9 上午09:45:38 venizeng
	 */
	public static final void gotoTeachLearnSkill(long learn_skillID) {
		Tools.debugPrintln("新手引导的学习技能ID = " + learn_skillID);
		UIMain main = (UIMain) UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_MAIN);
		if (main == null) {
			Tools.debugPrintln("无法进入新手引导的学习技能ID = " + learn_skillID);
			return;
		}
		ID_LEARN_SKILL = learn_skillID;
		main.m_state = main.STATE_LEARN_SKILL;
		main.m_yindaos = Tools.getStrArray("按右下边\"系\"，打开系统菜单", main.W_YINDAO);
	}

	/**
	 * 进入新手引导的设置快捷栏 2012-3-9 上午09:45:38 venizeng
	 */
	public static final void gotoTeachSetShortcut(byte pos, long set_skillID) {
		Tools.debugPrintln("新手引导的设置技能ID = " + set_skillID);
		UIMain main = (UIMain) UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_MAIN);
		if (main == null) {
			Tools.debugPrintln("无法进入新手引导的设置技能ID = " + set_skillID);
			return;
		}
		ID_SET_SKILL = set_skillID;
		POS_SET_SKILL = pos - 1;
		main.m_state = main.STATE_SET_SHORTCUT;
		main.m_yindaos = Tools.getStrArray("按右下边\"系\"，打开系统菜单", main.W_YINDAO);
	}

	public static final void gotoTeachOpenTask() {
		UIMain main = (UIMain) UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_MAIN);
		if (main == null) {
			return;
		}
		main.m_state = main.STATE_TASK;
		main.m_yindaos = Tools.getStrArray("按右下边\"系\"，打开系统菜单", main.W_YINDAO);
	}

	public void showNotify() {
		super.showNotify();
		updateShortcut();
	}

	public void initResource() {
		m_img_head_panel = UIManager.getInstance().coinImage(UIManager.RES_MAIN_HEAD_SELF);
		m_img_head_panel2 = UIManager.getInstance().coinImage(UIManager.RES_MAIN_HEAD_OTHER);
		m_img_shortcut_rect = UIManager.getInstance().coinImage(UIManager.RES_SHORTCUT_RECT);
		m_img_shortcut_rect2 = UIManager.getInstance().coinImage(UIManager.RES_SHORTCUT_RECT2);
		m_img_shortcut_decorate = UIManager.getInstance().coinImage(UIManager.RES_SHORTCUT_DECORATE);
		m_img_shortcut_arrow1 = UIManager.getInstance().coinImage(UIManager.RES_SHORTCUT_ARROW1);
		m_img_shortcut_arrow2 = UIManager.getInstance().coinImage(UIManager.RES_SHORTCUT_ARROW2);
		m_img_Leader = UIManager.getInstance().coinImage(UIManager.RES_MAIN_LEADER);
		m_img_spell = UIManager.getInstance().coinImage(UIManager.RES_FUZHOU);
		m_img_spell_huoyan = UIManager.getInstance().coinImage(UIManager.RES_FUZHOUHUOYAN);
		s_spell_x = AbstractGameScreen.SCREEN_WIDTH;
		s_spell_clipw = m_img_spell_huoyan.getWidth() / 3;
		m_img_gift = UIManager.getInstance().coinImage(UIManager.RES_GIFT);
		m_img_VimString = UIManager.getInstance().coinImage(UIManager.RES_VIM_STRING);
		m_img_VimFrame = UIManager.getInstance().coinImage(UIManager.RES_VIM_FRAME);
		m_img_xiegang = UIManager.getInstance().coinImage(UIManager.RES_XIEGANG);
	}

	protected void paintContent(Graphics g) {
//		g.setColor(0xff0000);
//		for(int i=11;i<=15;i++) {
//			int[] rect = main_normal[i];
//			g.fillRect(rect[0], rect[1], rect[2], rect[3]);
//		}
		
		drawPad(g);
		drawHead(g);
		drawVim(g);
		drawShowData(g);
		drawChat(g);
		drawExper(g);
		drawShortcut(g);
		drawCastingBar(g);
		drawOtherHead(g);
		drawThumbnail(g);
		drawMailAlert(g);
		drawFixAlert(g);
		drawFight(g);
		drawZhouFu(g);
		drawGift(g);
		drawMacro(g);
		drawBattlefieldScores(g);
		drawYindao(g);

	}

	private void drawPad(Graphics g) {
//		g.setColor(0xff0000);
//		for(int i=11;i<=15;i++) {
//			int[] rect = main_normal[i];
//			g.fillRect(rect[0], rect[1], rect[2], rect[3]);
//		}
		if (m_pad != null) {
			g.drawImage(m_pad, 0, AbstractGameScreen.SCREEN_HEIGHT, Graphics.LEFT|Graphics.BOTTOM);
		}
		if (m_fire != null) {
			g.drawImage(m_fire, 430, 250, Graphics.HCENTER|Graphics.VCENTER);
		}
	}
	private void drawVim(Graphics g) {
		int tempW = m_img_VimFrame.getWidth();
		int tempH = m_img_VimFrame.getHeight();
		int screenMidx = (AbstractGameScreen.SCREEN_WIDTH >> 1);
		int framew = 60;
		int frameh = 20;
		int bgFrame_x = screenMidx - (framew >> 1);
		int bgFrame_x2 = screenMidx + (framew >> 1);
		g.setColor(0xffffb6);
		g.drawLine(bgFrame_x, SHORTCUT_RECT_Y - 1, bgFrame_x2, SHORTCUT_RECT_Y - 1);
		g.drawLine(bgFrame_x, SHORTCUT_RECT_Y - frameh + 1, bgFrame_x2, SHORTCUT_RECT_Y - frameh + 1);
		g.setColor(0x610807);
		g.drawLine(bgFrame_x, SHORTCUT_RECT_Y - frameh, bgFrame_x2, SHORTCUT_RECT_Y - frameh);
		g.setColor(0x002a1b);
		g.fillRect(bgFrame_x, SHORTCUT_RECT_Y - frameh + 2, framew, frameh - 3);
		g.drawRegion(m_img_VimFrame, 0, 0, tempW, tempH, 0, bgFrame_x, SHORTCUT_RECT_Y, Tools.RIGHT_BOTTOM);
		g.drawRegion(m_img_VimFrame, 0, 0, tempW, tempH, 2, bgFrame_x2, SHORTCUT_RECT_Y, Tools.LEFT_BOTTOM);
		int ImgStrW = m_img_VimString.getWidth();
		g.drawImage(m_img_VimString, bgFrame_x, SHORTCUT_RECT_Y - 4, Tools.LEFT_BOTTOM);
		Tools.drawNumber(g, GameScene.s_img_num, bgFrame_x + ImgStrW + UITools.W_NUM * 3, SHORTCUT_RECT_Y - 6, UITools.W_NUM, UITools.H_NUM,
				GameManager.getInstance().m_role.m_jinglizhi_shengyu, 0, Tools.RIGHT_BOTTOM, false);
		g.drawImage(m_img_xiegang, bgFrame_x + ImgStrW + UITools.W_NUM * 3, SHORTCUT_RECT_Y - 6, Tools.LEFT_BOTTOM);
		Tools.drawNumber(g, GameScene.s_img_num, bgFrame_x + ImgStrW + UITools.W_NUM * 4, SHORTCUT_RECT_Y - 6, UITools.W_NUM, UITools.H_NUM,
				GameManager.getInstance().m_role.m_jinglizhi_zonggong, 0, Tools.LEFT_BOTTOM, false);
	}

	private void drawBattlefieldScores(Graphics g) {
		ActorRole role = GameManager.getInstance().m_role;
		role.drawBattlefieldScore(g);
	}

	private void drawMacro(Graphics g) {
		ActorRole role = GameManager.getInstance().m_role;
		if (role.m_macro_open && role.m_game_macro != null && role.m_macro_index >= 0 && role.m_macro_index < role.m_game_macro.length) {
			GameMacro gm = role.m_game_macro[role.m_macro_index];
			if (gm != null) {
				gm.drawIcon(g);
			}
		}
	}

	/** 咒符显示 开关 （0不显示 1显示关 2显示开 -1开关状态转换过程中） */
	public static byte s_spell_type = 1;
	public static final int s_spell_max = 21;// 开关位移差最大值
	public static byte s_spell_switch;// 开关 0 关 1 开
	public static int s_spell_y = 110;// 面板Y
	public static int s_spell_x;// 面板X
	public static int s_spell_srcx;// 开关位移数
	public static int s_spell_clipw;// 火焰的裁剪单位
	public static int s_spell_count;// 控制帧数的延迟
	public static int s_spell_loopx;// 帧数裁剪
	public static int s_spell_speed = 8;
	public static int s_spell_num = 0;// 符咒数量

	private void logicZhouFu() {
		// if (s_spell_type == 0) {// 关闭不显示
		// return;
		// }
		if (s_spell_type == -1) {// 过程中
			if (s_spell_switch == 1) {// 打开过程
				if (s_spell_srcx + s_spell_speed <= s_spell_max) {
					s_spell_srcx += s_spell_speed;
				} else {
					s_spell_type = 2;
					s_spell_srcx = s_spell_max;
				}
			} else {// 关闭过程
				if (s_spell_srcx - s_spell_speed >= 0) {
					s_spell_srcx -= s_spell_speed;
				} else {
					s_spell_srcx = 0;
					s_spell_type = 1;
				}
			}
		}

		if (s_spell_type == 2 || s_spell_type == -1) {// 开着
			if (s_spell_count < 1) {
				s_spell_count++;
			} else {
				if (s_spell_loopx < 42) {
					s_spell_loopx += s_spell_clipw;
				} else {
					s_spell_loopx = 0;
				}
				s_spell_count = 0;
			}
		} else {// 关着
			s_spell_count = 0;
			s_spell_loopx = 0;
		}
	}

	/**
	 * 绘制咒符
	 * 
	 * @param g
	 **/
	private void drawZhouFu(Graphics g) {
		if (s_spell_type == 0) {// 关闭不显示
			return;
		}
		int clipX = g.getClipX();
		int clipY = g.getClipY();
		int clipW = g.getClipWidth();
		int clipH = g.getClipHeight();
		g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
		int x = s_spell_x - s_spell_srcx - s_spell_max;
		int y = s_spell_y;
		if (s_spell_type == 1) {// 显示关
			g.drawImage(m_img_spell, x, y, 0);
		} else if (s_spell_type == 2 || s_spell_type == -1) {// 显示开或者开关过程中
			g.drawImage(m_img_spell, x, y, 0);
			if (s_spell_num > 0 && s_spell_type != -1) {
				g.setClip(x + 15, y - 11, s_spell_clipw, 41);
				g.drawImage(m_img_spell_huoyan, x - s_spell_loopx + 15, y - 11, 0);
			}
			if (GameScene.s_img_num != null) {// 绘制数量
				Tools.drawNumber(g, GameScene.s_img_num, x + 39, y + 23, 5, 7, s_spell_num, 0, Graphics.BOTTOM | Graphics.RIGHT, false);
			}
		}
		g.setClip(clipX, clipY, clipW, clipH);
	}
	
	/** 礼包 */
	private Image m_img_gift;
	public boolean m_gift_start;
	public long m_gift_time;
	public int m_gift_frame;
	
	/** 绘制礼包时间 */
	private void drawGift(Graphics g){
		if( !m_gift_start || m_img_gift == null || m_img_spell == null){
			return;
		}
		String temp = reFlashGiftTime();
		int u = 2;
		int w =(m_img_gift.getWidth()+u);
		int h =(m_img_spell.getHeight()+u);
		int x = AbstractGameScreen.SCREEN_WIDTH - w - AbstractGameScreen.s_font.stringWidth(temp);
		int y = s_spell_y + h;
		g.drawImage(m_img_gift, x, y, 0);
		g.setColor(0xFF0000);
		g.drawString(temp, x+w, y, 0);
		temp = null;
	}
	
	public void logicGiftTime(){
		if (m_gift_start) {
			if( ++m_gift_frame > 10 ){
				if (--m_gift_time < 0) {
					m_gift_start = false;
					m_gift_time = 0;
				}
				m_gift_frame = 0;
			}
			
		}
	}
	
	public String reFlashGiftTime(){
		StringBuffer buff = new StringBuffer();
		String temp = null;
		int h = (int)m_gift_time/ 3600;
		int m = (int)m_gift_time/ 60 % 60;
		int s = (int)m_gift_time % 60 % 60;

		if( h > 9 ){
			buff.append(h);
		}else if( h > 0 ){
			buff.append("0".concat(""+h));
		}else{
			buff.append("00");
		}
		buff.append(":");
		if( m > 9 ){
			buff.append(m);
		}else if( m > 0 ){
			buff.append("0".concat(""+m));
		}else{
			buff.append("00");
		}
		buff.append(":");
		if( s > 9 ){
			buff.append(s);
		}else{
			buff.append("0".concat(""+s));
		}
		temp = buff.toString();
		buff = null;
		return temp;
	}
	/**
	 * 设置礼包剩余时间
	 * @author zhao
	 * */
	public void recvSetGift(DataInputStream dis) throws IOException {
		try{
			long num = dis.readLong();
			m_gift_time = num;
			if( num > 0 ){
				m_gift_start = true;
			}else{
				m_gift_start = false;
				m_gift_time = 0;
			}
			m_gift_frame = 0;
			Tools.debugPrintln("recSetGift 礼包剩余时间="+m_gift_time);
		}catch (Exception e) {
			Tools.debugPrintln("礼包时间异常！"+e.toString());
		}
	}
	
	
//	public static void test(){
//		ByteArrayOutputStream baos = new ByteArrayOutputStream();
//		DataOutputStream dos = new DataOutputStream(baos);
//		
//		try {
//			int size = 3;
//			byte[] type = {0,1,2};
//			int[] colour = {0xFFFFFF,0x000000,0xFF0000};
//			String[] info = {"获得女人","巨阙剑","2"};
//			int[] num = {0,1,5};
//			dos.writeInt(size);
//			for(int i=0;i<size;i++){
//				dos.writeByte(type[i]);
//				dos.writeInt(colour[i]);
//				dos.writeUTF(info[i]);
//				dos.writeInt(num[i]);
//			}
//			
//		} catch (IOException e) {
//		}
//		ByteArrayInputStream das = new ByteArrayInputStream(baos.toByteArray());
//		DataInputStream dis = new DataInputStream(das);
//		try {
//			UIMain main = (UIMain) UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_MAIN);
//			if(main != null){
//				main.recvShowData(dis);
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//	}
	
//	public static Vector s_showData = new Vector();//存放显示数据容器
//	private static ShowData m_showdata;//显示数据的引用
//	private final int m_line = 60;//区域框高度
	
	/** 重置显示数据 */
//	public static void resetShowData(){
//		if( m_showdata != null){
//			m_showdata = null;
//		}
//		if( s_showData.size() > 0 ){
//			s_showData.removeAllElements();
//		}
//	}
	
	/** 接收显示数据 */
//	public void recvShowData(DataInputStream dis) throws IOException {
//		try{
//			 int size = dis.readInt();
//			 Tools.debugPrintln("显示数据 size="+size);
//			 ShowData data = new ShowData(size,getChatX(),getChatY(),m_line);
//			 for(int i=0;i<size;i++){
//				 byte type = dis.readByte();
//				 int _colour = dis.readInt();
//				 int _colourw = dis.readInt();
//				 String _info = dis.readUTF();
//				 int _num = dis.readInt();
//				 //Tools.debugPrintln("i="+i+";type="+type+";_colour="+_colour+";info="+_info+";_num="+_num);
//				 data = data.init(i, type, _colour, _colourw,_info, _num);
//			 }
//			 s_showData.addElement(data);
//			Tools.debugPrintln("recvShowData 添加数据");
//		}catch (Exception e) {
//			Tools.debugPrintln("显示数据异常！"+e.toString());
//		}
//	}
	
	public final String m_onekeytask = "点击继续任务";
	
	private void drawShowData(Graphics g){
		ActorRole actor = GameManager.getInstance().m_role;
		if( actor != null){
			if( actor.m_lv < 7 ){
				Tools.drawString(g, 0x110501, 0xffffff, m_onekeytask, AbstractGameScreen.SCREEN_WIDTH - AbstractGameScreen.s_font.stringWidth(m_onekeytask), getChatY() - AbstractGameScreen.FONT_H, 0);
//				g.setColor(0x0);
//				g.drawString(m_onekeytask, AbstractGameScreen.SCREEN_WIDTH - AbstractGameScreen.s_font.stringWidth(m_onekeytask), getChatY() - AbstractGameScreen.FONT_H, 0);
			}
		}
		if (Tools.DEBUG) {
			g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
			Tools.drawString(g, Tools.WHITE, Tools.BLACK, "FPS : " + GameManager.getInstance().m_scene.s_fps + " : " + UserScreen.PACKAGE_VERSION,
					(AbstractGameScreen.SCREEN_WIDTH >> 1) - 50, 0, Tools.HCENTER_TOP);
		}
//	    if( m_showdata != null ){
//	    	int clipX = g.getClipX();
//			int clipY = g.getClipY();
//			int clipW = g.getClipWidth();
//			int clipH = g.getClipHeight();
//			g.setClip(0, getChatY()-m_line, AbstractGameScreen.SCREEN_WIDTH, m_line);
//			m_showdata.draw(g);
//			g.setClip(clipX, clipY, clipW, clipH);
//	    }
	}
	
//	public void logicShowData(){
//		if( m_showdata == null && s_showData.size() == 0){
//			return;
//		}
//		ShowData data = (ShowData)s_showData.elementAt(0);
//		if( m_showdata == null ){
//			m_showdata = data;
//		}else{
//			if( m_showdata.m_life ){
//				if( data == m_showdata){
//					m_showdata = null;
//					s_showData.removeElementAt(0);
//					s_showData.trimToSize();
//				}	
//			}else{
//				m_showdata.run();
//			}
//		}
//	}
	
	/**
	 * 绘制新手引导 2012-3-9 上午10:01:05 venizeng
	 * 
	 * @param g
	 */
	private void drawYindao(Graphics g) {
		switch (m_state) {
		case STATE_EQUIP:
		case STATE_LEARN_SKILL:
		case STATE_SET_SHORTCUT:
		case STATE_TASK:
			// 绘制新手引导 - 右软键选中时
		{
			int clipX = g.getClipX();
			int clipY = g.getClipY();
			int clipW = g.getClipWidth();
			int clipH = g.getClipHeight();
			g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
			int iw = 4;
			int w = m_img_shortcut_decorate.getWidth() + (iw << 1);
			int h = m_img_shortcut_decorate.getHeight() + (iw << 1);
			int tempX = getDecorateX(false) - 5;
			int tempY = m_y + m_h - m_img_shortcut_decorate.getHeight() - iw;
			UITools.paintYindaoSelPos(g, tempX, tempY, w, h);
			UITools.paintYindaoArr(g, tempX, tempY, 4, 4);
			UITools.paintYindaoDesxribe(g, m_x + AbstractGameScreen.SCREEN_WIDTH - 140, m_y + AbstractGameScreen.SCREEN_HEIGHT - 100, W_YINDAO, m_yindaos);
			g.setClip(clipX, clipY, clipW, clipH);
		}
			break;
		}
	}

	public int getDecorateX(boolean isLeft) {
		// 两底角装饰物
		int iw = 9;
		if (isLeft) {
			return SHORTCUT_RECT_X - m_img_shortcut_decorate.getWidth() + iw;
		} else {
			return SHORTCUT_RECT_X + (SHORTCUT_RECT_W * 9) - iw;
		}
	}

	/**
	 * 绘制邮件提示 2012-3-9 上午09:43:35 venizeng
	 * 
	 * @param g
	 */
	private void drawMailAlert(Graphics g) {
		if (MailItem.s_num_newMail <= 0) {
			return;
		}
		if (UIManager.TIME % 6 < 3) {
			return;
		}
//		g.drawImage(UIManager.IMAGE_MAIL_UNREAD, m_x + m_w - UIManager.IMAGE_MAIL_UNREAD.getWidth() - 2, m_y + 100, 0);
		g.drawImage(UIManager.IMAGE_MAIL_UNREAD, m_x + X_ALERT,Y_MAIL, 0);
	}

	/**
	 * 修理道具提示 2012-3-9 上午09:43:35 venizeng
	 * 
	 * @param g
	 */
	private void drawFixAlert(Graphics g) {
		if (!GameManager.getInstance().m_role.m_isNeedFix) {
			return;
		}
		if (UIManager.TIME % 6 < 3) {
			return;
		}
//		g.drawImage(UIManager.IMAGE_FIX, m_x + m_w - UIManager.IMAGE_FIX.getWidth() - 2, m_y + 120, 0);
		g.drawImage(UIManager.IMAGE_FIX, m_x + X_ALERT, m_y + Y_FIX, 0);
	}

	private void drawFight(Graphics g) {
		if (GameManager.getInstance().m_role.m_status != AbstractGameActor.ACTOR_STATUS_ROLE_COMBAT) {
			return;
		}
		if (UIManager.TIME % 6 < 3) {
			return;
		}
		int tempX = m_x + HEAD_PANEL_SELF_X + HEAD_PANEL_W + UITools.IW_RECTS;
		int tempY = m_y + HEAD_PANEL_SELF_Y;
		g.drawImage(UIManager.IMAGE_FIGHT, tempX, tempY, 0);
	}

	/**
	 * 绘制缩略图
	 * 
	 * @param g
	 */
	private void drawThumbnail(Graphics g) {
		if (GameManager.getInstance().m_scene == null || GameScene.s_img_map_bg == null || GameScene.s_img_map_place == null || GameScene.s_img_num == null) {
			return;
		}
		int w = 66;
		int h = 26;
		// 绘制地址栏
		g.setClip(X_THUMBNAIL_MAP, Y_THUMBNAIL_MAP, w, h);
		g.drawImage(GameScene.s_img_map_place, X_THUMBNAIL_MAP, Y_THUMBNAIL_MAP, Tools.LEFT_TOP);
		g.setColor(Tools.WHITE);
		g.drawString(GameManager.getInstance().m_scene.m_name, X_THUMBNAIL_MAP + (w >> 1), Y_THUMBNAIL_MAP + (h - AbstractGameScreen.FONT_H) >> 1, Tools.HCENTER_TOP);
		// 绘制小地图
		int mapx = X_THUMBNAIL_MAP;
		int mapy = Y_THUMBNAIL_MAP + h - 2;
		g.setClip(mapx, mapy, ((GameScene) GameManager.getInstance().m_scene).THUMBNAIL_SHOW_WIDTH, ((GameScene) GameManager.getInstance().m_scene).THUMBNAIL_SHOW_HEIGHT);
		g.drawImage(GameScene.s_img_map_bg, mapx, mapy, Tools.LEFT_TOP);
		Vector m_thumbnail_list = ((GameScene) GameManager.getInstance().m_scene).m_thumbnail_list;
		if (m_thumbnail_list != null) {
			for (int i = 0; i < m_thumbnail_list.size(); i++) {
				AbstractGameActor actor = (AbstractGameActor) m_thumbnail_list.elementAt(i);
				switch (actor.m_head_state) {
				case ActorNPC.HEAD_STATE_YELLOW_QUESTION_MARK:// 1黄问号
					g.drawImage(GameScene.s_img_th_icon[ActorNPC.IMG_HS_Y_QUESTION_MARK], mapx + actor.m_thumbnail_x, mapy + actor.m_thumbnail_y, Tools.HCENTER_VCENTER);
					break;
				case ActorNPC.HEAD_STATE_BLUE_QUESTION_MARK:// 2蓝问号
					g.drawImage(GameScene.s_img_th_icon[ActorNPC.IMG_HS_B_QUESTION_MARK], mapx + actor.m_thumbnail_x, mapy + actor.m_thumbnail_y, Tools.HCENTER_VCENTER);
					break;
				case ActorNPC.HEAD_STATE_YELLOW_EXCLAMATION_MARK:// 4黄叹号
					g.drawImage(GameScene.s_img_th_icon[ActorNPC.IMG_HS_Y_EXCLAMATION_MARK], mapx + actor.m_thumbnail_x, mapy + actor.m_thumbnail_y, Tools.HCENTER_VCENTER);
					break;
				case ActorNPC.HEAD_STATE_BLUE_EXCLAMATION_MARK:// 8蓝叹号
					g.drawImage(GameScene.s_img_th_icon[ActorNPC.IMG_HS_B_EXCLAMATION_MARK], mapx + actor.m_thumbnail_x, mapy + actor.m_thumbnail_y, Tools.HCENTER_VCENTER);
					break;
				case ActorNPC.HEAD_STATE_GRAY_QUESTION_MARK:// 16灰问号
					g.drawImage(GameScene.s_img_th_icon[ActorNPC.IMG_HS_G_QUESTION_MARK], mapx + actor.m_thumbnail_x, mapy + actor.m_thumbnail_y, Tools.HCENTER_VCENTER);
					break;
				default:
					g.setColor(actor.m_thumbnail_color);
					g.fillRect(mapx + actor.m_thumbnail_x - 2, mapy + actor.m_thumbnail_y - 2, 4, 4);
					break;
				}
			}
		}
		// 绘制坐标栏
		g.setClip(X_THUMBNAIL_MAP + (w >> 1), mapy + ((GameScene) GameManager.getInstance().m_scene).THUMBNAIL_SHOW_HEIGHT, w, 11);
		mapy -= GameScene.s_img_map_bg.getHeight();
		Tools.drawNumber(g, GameScene.s_img_num, X_THUMBNAIL_MAP + (w >> 1) - 1, mapy + ((GameScene) GameManager.getInstance().m_scene).THUMBNAIL_SHOW_HEIGHT + 2, 5, 7,
				GameManager.getInstance().m_role.m_posX / GameManager.getInstance().m_scene.m_bg.m_tileW, 0, Tools.RIGHT_TOP, true);
		Tools.drawNumber(g, GameScene.s_img_num, X_THUMBNAIL_MAP + (w >> 1) + 6, mapy + ((GameScene) GameManager.getInstance().m_scene).THUMBNAIL_SHOW_HEIGHT + 2, 5, 7,
				GameManager.getInstance().m_role.m_posY / GameManager.getInstance().m_scene.m_bg.m_tileH, 0, Tools.LEFT_TOP, true);
		g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
		Tools.drawString(g, Tools.WHITE, Tools.BLACK, ".", X_THUMBNAIL_MAP + (w >> 1) + 1, mapy + ((GameScene) GameManager.getInstance().m_scene).THUMBNAIL_SHOW_HEIGHT - 5,
				Tools.LEFT_TOP);
		//绘制系统时间
		if( ++m_system_count > 20 ){
			m_system_count = 0;
			getSystemTime();
		}
		if (m_system_time != null) {
			mapy += GameScene.s_img_map_bg.getHeight();
			g.setColor(0xFFFFFF);
			int tempX = X_THUMBNAIL_MAP + ((GameScene.s_img_map_bg.getWidth() - AbstractGameScreen.s_font.stringWidth(m_system_time)) >> 1);
			int tempY = mapy + ((GameScene) GameManager.getInstance().m_scene).THUMBNAIL_SHOW_HEIGHT + 2;
			g.drawString(m_system_time, tempX, tempY, 0);
			tempX -= UIManager.IMAGE_SYSTEMTIME_XIAONAOZHONG.getWidth()+2;
			g.drawImage(UIManager.IMAGE_SYSTEMTIME_XIAONAOZHONG, tempX, tempY, 0);
		}
		if(GameManager.getInstance().m_areaType < 0 || GameManager.getInstance().m_areaType > 1){
			return;
		}
		Image img = UIManager.IMAGE_SMALLWORLD_AREA[GameManager.getInstance().m_areaType];
		if( img != null){
			int tempW = img.getWidth();
			int tempH = img.getHeight();
			int tempX = X_THUMBNAIL_MAP + ((GameScene.s_img_map_bg.getWidth() - tempW) >> 1);
			int tempY = mapy + ((GameScene) GameManager.getInstance().m_scene).THUMBNAIL_SHOW_HEIGHT - tempH -2;
			g.drawImage(img, tempX, tempY, 0);
		}
		
	}
	
    private String m_system_time;
    private int m_system_count;
    
	private void getSystemTime(){
		TimeZone tz = TimeZone.getDefault();
		Calendar ca = Calendar.getInstance(tz);
		int hour = ca.get( Calendar.HOUR );
        int min = ca.get( Calendar.MINUTE );
//        int sec = ca.get( Calendar.SECOND );
         int pm = ca.get( Calendar.AM_PM );
        hour = pm == 1 ? hour + 12 : hour;
        StringBuffer buff = new StringBuffer();
        if( pm == 0 ){
        	buff.append("");
        }
        if( hour > 9){
        	buff.append(hour+":");
        }else if( hour > 0 ){
        	buff.append("0"+hour+":");
        }else{
        	buff.append("00:");
        }
        if( min > 9 ){
        	buff.append(min);
        }else if( min > 0) {
        	buff.append("0"+min);
		}else{
			buff.append("00");
		}
        m_system_time = buff.toString();
        buff = null;
	}
	/**
	 * 绘制施法条
	 * 
	 * @param g
	 */
	private void drawCastingBar(Graphics g) {
		ActorRole role = GameManager.getInstance().m_role;
		if (role.m_castingTimeCounter > 0) {
			if (m_castingMsg != null) {
				g.setColor(Tools.WHITE);
				g.drawString(m_castingMsg, X_CASTING_BAR + 37, Y_CASTING_BAR, Tools.HCENTER_BOTTOM);
			}
			g.drawImage(GameManager.getInstance().img_casting_bar, X_CASTING_BAR, Y_CASTING_BAR, Tools.LEFT_TOP);
			g.setColor(Tools.RED);
			g.fillRect(X_CASTING_BAR + 7, Y_CASTING_BAR + 4, (role.m_castingTime - role.m_castingTimeCounter) * 60 / role.m_castingTime, 2);
		}

	}

	private void drawExper(Graphics g) {
		ActorRole role = GameManager.getInstance().m_role;
		int plan = 0;
		if (role.m_max_exp != 0) {
			plan = (int) (((long)EXPERIENCE_RECT_W * role.m_exp) / role.m_max_exp);
		}
		plan = plan >= EXPERIENCE_RECT_W ? EXPERIENCE_RECT_W : plan;
		int tempX = m_x + EXPERIENCE_RECT_X;
		int tempY = m_y + EXPERIENCE_RECT_Y;
		g.setColor(0x001111);
		g.fillRect(tempX, tempY, EXPERIENCE_RECT_W, EXPERIENCE_RECT_H);
		g.setColor(0xc80095);
		g.fillRect(tempX, tempY, plan, EXPERIENCE_RECT_H);
	}

	/**
	 * 绘制自己头像面板以及目标头像面板(包括buf)
	 * 
	 * @param g
	 */
	public void drawHead(Graphics g) {
		// /////////
		// 当前玩家
		// 底板
		g.drawImage(m_img_head_panel, HEAD_PANEL_SELF_X, HEAD_PANEL_SELF_Y, Tools.LEFT_TOP);
		// 头像
		m_role.m_anim.draw(g, HEAD_PANEL_SELF_X + HEAD_ICON_OFFSETX, HEAD_PANEL_SELF_Y + HEAD_ICON_OFFSETY, false, false,
				m_role.m_anim.m_actions[m_role.m_anim.m_actions.length - 1][0] & 0x03FF);
		// /队长标志
		if (GameManager.getInstance().m_role.m_gameID == GameManager.getInstance().m_role.m_leaderID) {
			// g.setClip(HEAD_PANEL2_OTHER_X + 1,
			// HEAD_PANEL2_OTHER_Y + (HEAD_PANEL2_H + OTHER_HEAD_JIANJU),
			// HEAD_PANEL2_W, HEAD_PANEL2_H);
			g.drawImage(m_img_Leader, HEAD_PANEL_SELF_X, HEAD_PANEL_SELF_Y + HEAD_PANEL_H, Tools.LEFT_BOTTOM);
		}
		// HP
		g.setColor(Tools.RED);
		g.fillRect(HEAD_PANEL_SELF_X + HEAD_HP_OFFSETX, HEAD_PANEL_SELF_Y + HEAD_HP_OFFSETY, (m_role.m_hp < 0 ? 0 : m_role.m_hp) * HEAD_HP_W / m_role.m_hpMax, HEAD_HP_H);
		// g.setColor(0xf3978f);
		// g.drawLine(HEAD_PANEL_SELF_X + HEAD_HP_OFFSETX,
		// HEAD_PANEL_SELF_Y + HEAD_HP_OFFSETY,
		// HEAD_PANEL_SELF_X + HEAD_HP_OFFSETX + (m_role.m_hp < 0 ? 0 :
		// m_role.m_hp) * HEAD_HP_W / m_role.m_hpMax - 1,
		// HEAD_PANEL_SELF_Y + HEAD_HP_OFFSETY);
		g.setColor(0xa71307);
		g.drawLine(HEAD_PANEL_SELF_X + HEAD_HP_OFFSETX, HEAD_PANEL_SELF_Y + HEAD_HP_OFFSETY + HEAD_HP_H - 1, HEAD_PANEL_SELF_X + HEAD_HP_OFFSETX
				+ (m_role.m_hp < 0 ? 0 : m_role.m_hp) * HEAD_HP_W / m_role.m_hpMax - 1, HEAD_PANEL_SELF_Y + HEAD_HP_OFFSETY + HEAD_HP_H - 1);
		// MP
		if (m_role.m_vocation[0] == ActorRole.VOCATION_JIAN_KE) {// 剑客
			g.setColor(Tools.YELLOW);
			for (int i = 0; i < m_role.m_mp; i++) {
				g.fillRect(HEAD_PANEL_SELF_X + HEAD_MP_OFFSETX + (HEAD_MP_JK_W + 1) * i, HEAD_PANEL_SELF_Y + HEAD_MP_OFFSETY, HEAD_MP_JK_W, HEAD_MP_H);
			}
		} else if (m_role.m_vocation[0] == ActorRole.VOCATION_WU_ZHE) {// 刀客
			// if (m_role.m_status ==
			// AbstractGameActor.ACTOR_STATUS_ROLE_COMBAT) {
			GameScene scene = (GameScene) GameManager.getInstance().m_scene;
			if (m_role.m_mp == 0) {// 全蓝色
				if (scene.m_timer % 4 < 2) {
					g.setColor(Tools.WHITE);
				} else {
					g.setColor(Tools.BLUE);
				}
				g.fillRect(HEAD_PANEL_SELF_X + HEAD_MP_OFFSETX, HEAD_PANEL_SELF_Y + HEAD_MP_OFFSETY, HEAD_MP_W, HEAD_MP_H);

				// 刻度条
				g.setColor(Tools.GREEN);
				g.fillRect(HEAD_PANEL_SELF_X + HEAD_MP_OFFSETX, HEAD_PANEL_SELF_Y + HEAD_MP_OFFSETY, 2, HEAD_MP_H);

				if (scene.m_timer % 2 < 1) {
					g.setColor(Tools.WHITE);
				} else {
					g.setColor(Tools.BLACK);
				}
				g.drawRect(HEAD_PANEL_SELF_X + HEAD_MP_OFFSETX - 1, HEAD_PANEL_SELF_Y + HEAD_MP_OFFSETY - 1, 3, HEAD_MP_H + 1);
			} else if (m_role.m_mp == m_role.m_mpMax) {// 全红
				if (scene.m_timer % 4 < 2) {
					g.setColor(Tools.WHITE);
				} else {
					g.setColor(Tools.RED);
				}
				g.fillRect(HEAD_PANEL_SELF_X + HEAD_MP_OFFSETX, HEAD_PANEL_SELF_Y + HEAD_MP_OFFSETY, HEAD_MP_W, HEAD_MP_H);
				// 刻度条
				g.setColor(Tools.GREEN);
				g.fillRect(HEAD_PANEL_SELF_X + HEAD_MP_OFFSETX + HEAD_MP_W, HEAD_PANEL_SELF_Y + HEAD_MP_OFFSETY, 2, HEAD_MP_H);

				if (scene.m_timer % 2 < 1) {
					g.setColor(Tools.WHITE);
				} else {
					g.setColor(Tools.BLACK);
				}
				g.drawRect(HEAD_PANEL_SELF_X + HEAD_MP_OFFSETX + HEAD_MP_W - 1, HEAD_PANEL_SELF_Y + HEAD_MP_OFFSETY - 1, 3, HEAD_MP_H + 1);
			} else {
				// 基本条
				g.setColor(Tools.BLUE);
				g.fillRect(HEAD_PANEL_SELF_X + HEAD_MP_OFFSETX, HEAD_PANEL_SELF_Y + HEAD_MP_OFFSETY, HEAD_MP_W >> 1, HEAD_MP_H);
				g.setColor(Tools.MAGENTA);
				g.fillRect(HEAD_PANEL_SELF_X + HEAD_MP_OFFSETX + (HEAD_MP_W >> 1), HEAD_PANEL_SELF_Y + HEAD_MP_OFFSETY, (HEAD_MP_W - (HEAD_MP_W >> 1)), HEAD_MP_H);
				g.setColor(Tools.YELLOW);
				g.fillRect(HEAD_PANEL_SELF_X + HEAD_MP_OFFSETX + (HEAD_MP_W >> 1), HEAD_PANEL_SELF_Y + HEAD_MP_OFFSETY, 2, HEAD_MP_H);
				// 刻度条
				g.setColor(Tools.GREEN);
				g.fillRect(HEAD_PANEL_SELF_X + HEAD_MP_OFFSETX + (m_role.m_mp * HEAD_MP_W / m_role.m_mpMax), HEAD_PANEL_SELF_Y + HEAD_MP_OFFSETY, 2, HEAD_MP_H);
				g.setColor(Tools.BLACK);
				g.drawRect(HEAD_PANEL_SELF_X + HEAD_MP_OFFSETX - 1 + (m_role.m_mp * HEAD_MP_W / m_role.m_mpMax), HEAD_PANEL_SELF_Y + HEAD_MP_OFFSETY - 1, 3, HEAD_MP_H + 1);
			}

			// }
			// else {
			// //基本条
			// g.setColor(Tools.BLUE);
			// g.fillRect(HEAD_PANEL_SELF_X + HEAD_MP_OFFSETX, HEAD_PANEL_SELF_Y
			// + HEAD_MP_OFFSETY, HEAD_MP_W >> 1,
			// HEAD_MP_H);
			// g.setColor(Tools.MAGENTA);
			// g.fillRect(HEAD_PANEL_SELF_X + HEAD_MP_OFFSETX + (HEAD_MP_W >>
			// 1), HEAD_PANEL_SELF_Y + HEAD_MP_OFFSETY,
			// (HEAD_MP_W - (HEAD_MP_W >> 1)), HEAD_MP_H);
			// g.setColor(Tools.YELLOW);
			// g.fillRect(HEAD_PANEL_SELF_X + HEAD_MP_OFFSETX + (HEAD_MP_W >>
			// 1), HEAD_PANEL_SELF_Y + HEAD_MP_OFFSETY,
			// 2, HEAD_MP_H);
			// //刻度条
			// g.setColor(Tools.GREEN);
			// g.fillRect(HEAD_PANEL_SELF_X + HEAD_MP_OFFSETX + (HEAD_MP_W >>
			// 1), HEAD_PANEL_SELF_Y + HEAD_MP_OFFSETY,
			// 2, HEAD_MP_H);
			// g.setColor(Tools.BLACK);
			// g.drawRect(HEAD_PANEL_SELF_X + HEAD_MP_OFFSETX + (HEAD_MP_W >> 1)
			// - 1, HEAD_PANEL_SELF_Y +
			// HEAD_MP_OFFSETY - 1, 3, HEAD_MP_H + 1);
			// }
		} else {
			g.setColor(Tools.BLUE);
			g.fillRect(HEAD_PANEL_SELF_X + HEAD_MP_OFFSETX, HEAD_PANEL_SELF_Y + HEAD_MP_OFFSETY, m_role.m_mp * HEAD_MP_W / m_role.m_mpMax, HEAD_MP_H);
		}
		// 等级
		Tools.drawNumber(g, GameScene.s_img_num, HEAD_PANEL_SELF_X + HEAD_LVL_SELF_OFFSETX, HEAD_PANEL_SELF_Y + HEAD_LVL_OFFSETY, HEAD_LVL_NUM_W, HEAD_LVL_NUM_H, m_role.m_lv, 0,
				Graphics.TOP | Graphics.RIGHT, false);
		// buffer相关
		ActorBuffer buffer;
		for (int i = 0; i < m_role.m_buf.size(); i++) {
			buffer = (ActorBuffer) (m_role.m_buf.elementAt(i));
			buffer.draw(g, HEAD_PANEL_SELF_X + i * ActorBuffer.SIZE_IMG_ICON[0], HEAD_PANEL_SELF_Y + BUFFER_Y, Graphics.TOP | Graphics.LEFT);
		}
		for (int i = 0; i < m_role.m_debuf.size(); i++) {
			buffer = (ActorBuffer) (m_role.m_debuf.elementAt(i));
			buffer.draw(g, HEAD_PANEL_SELF_X + i * ActorBuffer.SIZE_IMG_ICON[0], HEAD_PANEL_SELF_Y + BUFFER_Y + ActorBuffer.SIZE_IMG_ICON[1], Graphics.TOP | Graphics.LEFT);
		}

		// /////////
		// 目标
		AbstractGameActor actor = m_role.m_targetActor;
		if (actor != null) {
			// 底板
			AbstractGameScreen.drawRegion(g, m_img_head_panel, 0, 0, m_img_head_panel.getWidth(), m_img_head_panel.getHeight(), Sprite.TRANS_MIRROR, HEAD_PANEL_TARGET_X,
					HEAD_PANEL_TARGET_Y, Graphics.TOP | Graphics.RIGHT);
			// g.drawImage(m_img_head_panel, HEAD_PANEL_TARGET_X,
			// HEAD_PANEL_TARGET_Y, Graphics.TOP | Graphics.RIGHT);
			// 头像
			int frameId = -1;
			if (actor instanceof ActorNPC) {
				if (actor.m_anim.m_actions != null) {
					if (actor.m_anim.m_actions[actor.m_anim.m_actions.length - 1].length == 0) {
						Tools.debugPrintln("anim " + actor.m_anim.m_resHead.m_url + " 头像是空的!");
					} else {
						frameId = actor.m_anim.m_actions[actor.m_anim.m_actions.length - 1][0] & 0x03FF;
					}
				}
			} else if (actor instanceof ActorRole) {
				frameId = actor.m_anim.m_actions[actor.m_anim.m_actions.length - 1][0] & 0x03FF;
			}
			if (frameId != -1) {
				actor.m_anim.draw(g, HEAD_PANEL_TARGET_X - HEAD_ICON_OFFSETX, HEAD_PANEL_TARGET_Y + HEAD_ICON_OFFSETY, true, false, frameId);
			}
			// HP
			g.setColor(Tools.RED);
			g.fillRect(HEAD_PANEL_TARGET_X - HEAD_HP_OFFSETX - actor.m_hp * HEAD_HP_W / actor.m_hpMax, HEAD_PANEL_TARGET_Y + HEAD_HP_OFFSETY, actor.m_hp * HEAD_HP_W
					/ actor.m_hpMax, HEAD_HP_H);
			// MP
			if (actor instanceof ActorRole) {
				// 剑客
				if (((ActorRole) actor).m_vocation[0] == ActorRole.VOCATION_JIAN_KE) {
					g.setColor(Tools.YELLOW);
					for (int i = 0; i < actor.m_mp; i++) {
						g.fillRect(HEAD_PANEL_TARGET_X - HEAD_MP_OFFSETX - (HEAD_MP_JK_W + 1) * (i + 1) + 1, HEAD_PANEL_TARGET_Y + HEAD_MP_OFFSETY, HEAD_MP_JK_W, HEAD_MP_H);
					}
				} else {
					g.setColor(Tools.BLUE);
					g.fillRect(HEAD_PANEL_TARGET_X - HEAD_MP_OFFSETX - actor.m_mp * HEAD_MP_W / actor.m_mpMax, HEAD_PANEL_TARGET_Y + HEAD_MP_OFFSETY, actor.m_mp * HEAD_MP_W
							/ actor.m_mpMax, HEAD_MP_H);
				}
			} else {
				g.setColor(Tools.BLUE);
				if (actor.m_mpMax > 0) {
					g.fillRect(HEAD_PANEL_TARGET_X - HEAD_MP_OFFSETX - actor.m_mp * HEAD_MP_W / actor.m_mpMax, HEAD_PANEL_TARGET_Y + HEAD_MP_OFFSETY, actor.m_mp * HEAD_MP_W
							/ actor.m_mpMax, HEAD_MP_H);
				}
			}
			// 等级
			Tools.drawNumber(g, GameScene.s_img_num, HEAD_PANEL_TARGET_X - HEAD_LVL_TARGET_OFFSETX, HEAD_PANEL_TARGET_Y + HEAD_LVL_OFFSETY, HEAD_LVL_NUM_W, HEAD_LVL_NUM_H,
					actor.m_lv, 0, Graphics.TOP | Graphics.RIGHT, false);
			// buffer相关
			for (int i = 0; i < actor.m_buf.size(); i++) {
				buffer = (ActorBuffer) (actor.m_buf.elementAt(i));
				buffer.draw(g, HEAD_PANEL_TARGET_X - i * ActorBuffer.SIZE_IMG_ICON[0], HEAD_PANEL_TARGET_Y + BUFFER_Y, Graphics.TOP | Graphics.RIGHT);
			}
			for (int i = 0; i < actor.m_debuf.size(); i++) {
				buffer = (ActorBuffer) (actor.m_debuf.elementAt(i));
				buffer.draw(g, HEAD_PANEL_TARGET_X - i * ActorBuffer.SIZE_IMG_ICON[0], HEAD_PANEL_TARGET_Y + BUFFER_Y + ActorBuffer.SIZE_IMG_ICON[1], Graphics.TOP | Graphics.RIGHT);
			}
		}

	}

	/**
	 * 绘制队友头像
	 * 
	 * @param g
	 */
	private void drawOtherHead(Graphics g) {
		Vector rolelist = GameManager.getInstance().m_role.m_roleTeam;
		if (rolelist == null || rolelist.size() == 0) {
			return;
		}
		int i = 0;
		int rolelistsize = rolelist.size();
		for (int n = 0; n < rolelistsize; n++) {
			ActorRole role = (ActorRole) rolelist.elementAt(n);

			if (role.m_gameID == GameManager.getInstance().m_role.m_gameID) {
				continue;
			}
			// /////////
			// 队友头像
			if (role.m_online) { // 在线
				switch (role.m_vocation[0]) {
				case ActorRole.VOCATION_JIAN_KE:

					g.setClip(HEAD_PANEL2_OTHER_X, HEAD_PANEL2_OTHER_Y + (HEAD_PANEL2_H + OTHER_HEAD_JIANJU) * i, HEAD_PANEL2_W, HEAD_PANEL2_H);
					g.drawImage(m_img_head_panel2, HEAD_PANEL2_OTHER_X, HEAD_PANEL2_OTHER_Y + (HEAD_PANEL2_H + OTHER_HEAD_JIANJU) * i, Tools.LEFT_TOP);
					break;
				case ActorRole.VOCATION_WU_ZHE:
					g.setClip(HEAD_PANEL2_OTHER_X, HEAD_PANEL2_OTHER_Y + (HEAD_PANEL2_H + OTHER_HEAD_JIANJU) * i, HEAD_PANEL2_W, HEAD_PANEL2_H);
					g.drawImage(m_img_head_panel2, HEAD_PANEL2_OTHER_X - HEAD_PANEL2_W, HEAD_PANEL2_OTHER_Y + (HEAD_PANEL2_H + OTHER_HEAD_JIANJU) * i, Tools.LEFT_TOP);
					break;
				case ActorRole.VOCATION_DAO_SHI:
					g.setClip(HEAD_PANEL2_OTHER_X, HEAD_PANEL2_OTHER_Y + (HEAD_PANEL2_H + OTHER_HEAD_JIANJU) * i, HEAD_PANEL2_W, HEAD_PANEL2_H);
					g.drawImage(m_img_head_panel2, HEAD_PANEL2_OTHER_X - HEAD_PANEL2_W * 2, HEAD_PANEL2_OTHER_Y + (HEAD_PANEL2_H + OTHER_HEAD_JIANJU) * i, Tools.LEFT_TOP);
					break;
				}
				// 绘制等级
				// int w = 15;
				// int h = 8;
				// g.setClip(HEAD_PANEL2_OTHER_X, HEAD_PANEL2_OTHER_Y +
				// (HEAD_PANEL2_H + OTHER_HEAD_JIANJU) * i
				// , HEAD_PANEL2_W, HEAD_PANEL2_H);
				// g.setColor(Tools.YELLOW);
				// g.drawRect(HEAD_PANEL2_OTHER_X,
				// HEAD_PANEL2_OTHER_Y + (HEAD_PANEL2_H + OTHER_HEAD_JIANJU) *
				// (i + 1) - (h + 1), w, h);
				// g.setColor(Tools.BLACK);
				// g.fillRect(HEAD_PANEL2_OTHER_X + 1,
				// HEAD_PANEL2_OTHER_Y + (HEAD_PANEL2_H + OTHER_HEAD_JIANJU) *
				// (i + 1) - (h + 1) + 1,
				// w - 1, h - 1);
				Tools.drawNumber(g, GameScene.s_img_num, HEAD_PANEL2_OTHER_X + HEAD_PANEL2_W - 2, HEAD_PANEL2_OTHER_Y + (HEAD_PANEL2_H + OTHER_HEAD_JIANJU) * (i + 1)
						- OTHER_HEAD_JIANJU, HEAD_LVL_NUM_W, HEAD_LVL_NUM_H, role.m_grade, 0, Tools.RIGHT_BOTTOM, false);
				// 绘制名字

				g.setClip(HEAD_PANEL2_OTHER_X + HEAD_PANEL2_W + HEAD_PANEL2_HP_W, HEAD_PANEL2_OTHER_Y + (HEAD_PANEL2_H + OTHER_HEAD_JIANJU) * i, 30, HEAD_PANEL2_H);
				// g.setColor(Tools.YELLOW);
				String str = role.m_name;
				StringBuffer name = new StringBuffer();
				name.append(str.charAt(0));
				int length = str.length();
				for (int j = 0; j < length - 1; j++) {
					name.append('.');
				}
				Tools.drawString(g, Tools.YELLOW, Tools.BLACK, name.toString(), HEAD_PANEL2_OTHER_X + HEAD_PANEL2_W + 1 + HEAD_PANEL2_HP_W + 2, HEAD_PANEL2_OTHER_Y
						+ (HEAD_PANEL2_H + OTHER_HEAD_JIANJU) * i + HEAD_PANEL2_H, Tools.LEFT_BOTTOM);
			} else { // 不在线
				g.setClip(HEAD_PANEL2_OTHER_X, HEAD_PANEL2_OTHER_Y + (HEAD_PANEL2_H + OTHER_HEAD_JIANJU) * i, HEAD_PANEL2_W, HEAD_PANEL2_H);
				g.drawImage(m_img_head_panel2, HEAD_PANEL2_OTHER_X, HEAD_PANEL2_OTHER_Y + (HEAD_PANEL2_H + OTHER_HEAD_JIANJU) * i - HEAD_PANEL2_H, Tools.LEFT_TOP);
			}
			// HP
			g.setClip(HEAD_PANEL2_OTHER_X + HEAD_PANEL2_W, HEAD_PANEL2_OTHER_Y + (HEAD_PANEL2_H + OTHER_HEAD_JIANJU) * i, HEAD_PANEL2_HP_W, HEAD_PANEL2_HP_H);
			g.setColor(Tools.YELLOW);
			g.drawRect(HEAD_PANEL2_OTHER_X + HEAD_PANEL2_W, HEAD_PANEL2_OTHER_Y + (HEAD_PANEL2_H + OTHER_HEAD_JIANJU) * i, HEAD_PANEL2_HP_W - 1, HEAD_PANEL2_HP_H - 1);
			g.setColor(Tools.BLACK);
			g.fillRect(HEAD_PANEL2_OTHER_X + HEAD_PANEL2_W + 1, HEAD_PANEL2_OTHER_Y + (HEAD_PANEL2_H + OTHER_HEAD_JIANJU) * i + 1, HEAD_PANEL2_HP_W - 2, HEAD_PANEL2_HP_H - 2);
			if (role.m_hpMax != 0) {
				g.setColor(Tools.RED);
				g.fillRect(HEAD_PANEL2_OTHER_X + HEAD_PANEL2_W + 1, HEAD_PANEL2_OTHER_Y + (HEAD_PANEL2_H + OTHER_HEAD_JIANJU) * i + 1 + (role.m_hpMax - role.m_hp)
						* HEAD_PANEL2_HP_H, HEAD_PANEL2_HP_W - 2, (role.m_hp * HEAD_PANEL2_HP_H / role.m_hpMax));
			}

			if (role.m_gameID == GameManager.getInstance().m_role.m_leaderID) {
				g.setClip(HEAD_PANEL2_OTHER_X, HEAD_PANEL2_OTHER_Y + (HEAD_PANEL2_H + OTHER_HEAD_JIANJU) * i, HEAD_PANEL2_W, HEAD_PANEL2_H);
				g.drawImage(m_img_Leader, HEAD_PANEL2_OTHER_X, HEAD_PANEL2_OTHER_Y + (HEAD_PANEL2_H + OTHER_HEAD_JIANJU) * i, Tools.LEFT_TOP);
			}

			i++;
		}

	}

	private Object[] m_shortcut_data = new Object[8];

	private void drawShortcut(Graphics g) {
		int i = 0;
		// 技能栏
		Object obj = null;
		int tempX = SHORTCUT_RECT_X;
		int tempY = SHORTCUT_RECT_Y;
		for (i = 0; i < 8; i++) {
			g.drawImage(m_img_shortcut_rect, tempX, tempY, Tools.LEFT_TOP);
			obj = m_shortcut_data[i];
			if (obj != null) {
				if (obj instanceof RoleCombatSkill) {
					RoleCombatSkill skill = (RoleCombatSkill) obj;
					// if (i == 2) {
					// System.out.println("");
					// }
					skill.drawIcon(g, tempX + 2, tempY + 2, Tools.LEFT_TOP);
				} else if (obj instanceof ActorItem) {
					ActorItem actorItem = (ActorItem) obj;
					actorItem.drawIcon(g, tempX + 2, tempY + 2, Tools.LEFT_TOP);
				} else if (obj instanceof MenuFunction) {
					MenuFunction function = (MenuFunction) obj;
					function.drawIcon(g, tempX + 2, tempY + 2);
				}
			}
//			Tools.drawNumber(g, GameScene.s_img_num, tempX, tempY, UITools.W_NUM, UITools.H_NUM, i + 1, 0, Tools.LEFT_TOP, false);
			Tools.drawNumber(g, GameScene.s_img_num, tempX +UITools.W_BAG, tempY + UITools.H_BAG, UITools.W_NUM, UITools.H_NUM, i + 1, 0, Graphics.BOTTOM | Graphics.RIGHT, false);
			//
			tempX += SHORTCUT_RECT_W;
		}
		// 技能栏跳转键
		i = 8;
		g.drawImage(m_img_shortcut_rect2, tempX, tempY, Tools.LEFT_TOP);
		g.drawImage(m_img_shortcut_arrow1, tempX + (SHORTCUT_RECT_W >> 1), tempY + (SHORTCUT_RECT_H >> 1), Graphics.BOTTOM | Graphics.HCENTER);
		AbstractGameScreen.drawRegion(g, m_img_shortcut_arrow2, 0, 0, m_img_shortcut_arrow2.getWidth(), m_img_shortcut_arrow2.getHeight(), Sprite.TRANS_MIRROR_ROT180, tempX
				+ (SHORTCUT_RECT_W >> 1), tempY + (SHORTCUT_RECT_H >> 1), Graphics.TOP | Graphics.HCENTER);

		Tools.drawNumber(g, GameScene.s_img_num, tempX +UITools.W_BAG, tempY +UITools.H_BAG, UITools.W_NUM, UITools.H_NUM, i + 1, 0, Graphics.BOTTOM | Graphics.RIGHT, false);

		//
		// 两底角装饰物
		int ih = 0;
		tempY = AbstractGameScreen.SCREEN_HEIGHT - ih;
		int iww = 17;
		int ihh = -10;
		tempX = getDecorateX(true);
		g.drawImage(m_img_shortcut_decorate, tempX, tempY, Tools.LEFT_BOTTOM);
		g.drawImage(UIManager.IMAGE_LEFT_SOFT, tempX + iww, tempY + ihh, Tools.LEFT_BOTTOM);
		tempX = getDecorateX(false);
		AbstractGameScreen.drawRegion(g, m_img_shortcut_decorate, 0, 0, m_img_shortcut_decorate.getWidth(), m_img_shortcut_decorate.getHeight(), Sprite.TRANS_MIRROR, tempX, tempY,
				Tools.LEFT_BOTTOM);
		g.drawImage(UIManager.IMAGE_RIGHT_SOFT, tempX + iww, tempY + ihh, Tools.LEFT_BOTTOM);
	}

	private Vector m_items = new Vector();// 显示在
	private int m_y_top_chat;// 聊天的顶部位移
	private final int COLOR_CHAT = 0x66000000;
    
	
	/** 获取聊天记录框的起始 X Y */
	public int getChatX(){
	   return m_x;
	}
	public int getChatY(){
		return m_y + m_h - EXPERIENCE_RECT_H - H_CHAT - H_SHORTCUT;
	}
	
	/**
	 * 绘制聊天记录
	 * 
	 * @param g
	 * @param x
	 * @param y
	 * @param w
	 * @param h
	 */
	private void drawChat(Graphics g) {
		if (m_items == null) {
			return;
		}
		int size = m_items.size();
		if (size == 0) {
			return;
		}
		TIME_CHAT--;
		if (TIME_CHAT <= 0) {
			return;
		} else if (TIME_CHAT < H_CHAT) {// 预留做动画

		} else if (TIME_CHAT > (TIMEER_CHAT - H_CHAT)) {

		}
		int x = m_x;
		int y = m_y + m_h - EXPERIENCE_RECT_H - H_CHAT - H_SHORTCUT;
		int w = m_w;
		int h = H_CHAT;
		UITools.drawFillRectAlpha(g, x, y, w, h, COLOR_CHAT);
		int clipX = g.getClipX();
		int clipY = g.getClipY();
		int clipW = g.getClipWidth();
		int clipH = g.getClipHeight();
		g.setClip(x, y, w, h);
		int tempX = x + UITools.IW_RECT_CONTENT;
		int tempY = y + m_y_top_chat;
		try {
			for (int i = 0, length = m_items.size(); i < length; i++) {
				int index = size - length + i;
				if (index < 0) {
					break;
				}
				ChatItem item = (ChatItem) m_items.elementAt(index);
				if (item == null) {
					continue;
				}
				item.paintChatItem(g, tempX, tempY, w, h, false);
				tempY += item.getH();
			}

		} catch (Exception e) {
		}
		g.setClip(clipX, clipY, clipW, clipH);
	}


	/**
	 * 更新快捷栏
	 */
	public static final void updateShortcut() {
		Tools.debugPrintln("记得主界面要更新快捷栏");
		UIMain main = (UIMain) UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_MAIN);
		if (main == null) {
			return;
		}
		long[][][] shoutcutData = GameManager.getInstance().m_role.m_shortcut;
		if (shoutcutData == null) {
			return;
		}
		Object[] objects = new Object[shoutcutData[0].length];
		int index_switch = GameManager.getInstance().m_role.m_shortcut_bar;
		ActorRole role= GameManager.getInstance().m_role ;
		for (int i = 0; i < objects.length; i++) {
			main.m_shortcut_data[i] = role.getShortcutData(index_switch, i);
		}
	}

	/**
	 * 当技能发生变化的时候修改宏 2012-4-14 下午06:12:13 venizeng
	 * 
	 * @param oldId
	 * @param newId
	 */
	public static final void updateMarco(long oldId, long newId, int skillSwitchIndex, int skillIndex) {
		ActorRole role = GameManager.getInstance().m_role;
		RoleCombatSkill[][] skills = role.m_roleCombatSkill;
		GameMacro[] marco = role.m_game_macro;
		if (marco == null) {
			return;
		}
		for (int i = 0; i < marco.length; i++) {
			if (marco[i] == null) {
				continue;
			}
			long[][] actions = marco[i].m_actionId;
			if (actions == null) {
				continue;
			}
			for (int j = 0; j < actions.length; j++) {
				if (actions[j] == null) {
					continue;
				}
				if (actions[j][GameMacro.MACRO_INDEX_TYPE] != AbstractGameActor.ACTION_TYPE_SKILL) {
					continue;
				}
				if (actions[j][GameMacro.MACRO_INDEX_ID] == oldId) {
					if (skills[skillSwitchIndex][skillIndex].m_level <= 0) {//
						actions[j][GameMacro.MACRO_INDEX_TYPE] = 0;
						actions[j][GameMacro.MACRO_INDEX_ID] = 0;
					} else {
						actions[j][GameMacro.MACRO_INDEX_ID] = newId;
					}
				}
			}
		}
	}

	/**
	 * 当技能发生变化的时候修改宏 2012-4-14 下午06:12:13 venizeng
	 * 
	 * @param oldId
	 * @param newId
	 */
	public static final void deleteMarco(long id) {
		ActorRole role = GameManager.getInstance().m_role;
		GameMacro[] marco = role.m_game_macro;
		if (marco == null) {
			return;
		}
		for (int i = 0; i < marco.length; i++) {
			if (marco[i] == null) {
				continue;
			}
			long[][] actions = marco[i].m_actionId;
			if (actions == null) {
				continue;
			}
			for (int j = 0; j < actions.length; j++) {
				if (actions[j] == null) {
					continue;
				}
				if (actions[j][GameMacro.MACRO_INDEX_TYPE] != AbstractGameActor.ACTION_TYPE_SKILL) {
					continue;
				}
				if (actions[j][GameMacro.MACRO_INDEX_ID] == id) {
					actions[j][GameMacro.MACRO_INDEX_TYPE] = 0;
					actions[j][GameMacro.MACRO_INDEX_ID] = 0;
				}
			}
		}
	}

	/**
	 * 更新聊天
	 */
	public static final void updateChat() {
		UIMain main = (UIMain) UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_MAIN);
		if (main == null) {
			return;
		}
		Vector vector = sieveChatItem(GameManager.getInstance().m_role.m_list_chats);
		int size = vector.size();
		if (size < 1) {
			main.m_y_top_chat = 0;
			if( vector != null ){
				vector.removeAllElements();
				vector = null;
			}
			return;
		}
		int w_rect = main.m_w - (UITools.IW_RECT_CONTENT << 1);// 聊天框的显示宽度
		main.m_items.removeAllElements();
		if (main.TIME_CHAT == 0) {//
			ChatItem item = ((ChatItem) vector.elementAt(vector.size() - 1)).clone();
			main.m_items.addElement(item);
			int sumH = item.init(w_rect);
			int h = sumH - main.H_CHAT;
			if (h <= 0) {
				main.m_y_top_chat = 0;
			} else {
				main.m_y_top_chat = -h;
			}
		} else {
			// 修改聊天内容
			int sumH = 0;
			for (int i = size - 1; i >= 0; i--) {
				ChatItem item = ((ChatItem) vector.elementAt(i)).clone();
				main.m_items.addElement(item);
				int H = item.init(w_rect);
				sumH += H;
				if (sumH >= main.H_CHAT) {
					break;
				}
			}
			int h = sumH - main.H_CHAT;
			if (h <= 0) {
				main.m_y_top_chat = 0;
			} else {
				main.m_y_top_chat = -h;
			}
		}
		//
		if( vector != null ){
			vector.removeAllElements();
			vector = null;
		}
		main.TIME_CHAT = main.TIMEER_CHAT;// 重设计时器
	}
    
	public static Vector sieveChatItem(Vector v){
		if( v == null ){
			return null;
		}
		int size = v.size();
		if( size < 1){
			return null;
		}
		Vector vc = new Vector();
	    for(int i=0;i<size;i++){
	    	ChatItem item = (ChatItem)v.elementAt(i);
	    	byte state = 1;
			switch (item.m_type) {
				case ChatItem.TYPE_SI:
					state = GameManager.s_system_infos[GameManager.SET_CHANNEL_PRIVATE];
					break;
				case ChatItem.TYPE_TEAM:
					state = GameManager.s_system_infos[GameManager.SET_CHANNEL_RANKS];
					break;
				case ChatItem.TYPE_WORLD:
					state = GameManager.s_system_infos[GameManager.SET_CHANNEL_WORLD];
					break;
				case ChatItem.TYPE_XI:
					state = GameManager.s_system_infos[GameManager.SET_CHANNEL_SYSTEM];
					break;
				case ChatItem.TYPE_FAMILY:
					state = GameManager.s_system_infos[GameManager.SET_CHANNEL_FMAILY];
					break;
				case ChatItem.TYPE_REALM:
					state = GameManager.s_system_infos[GameManager.SET_CHANNEL_CAMP];
					break;
			}
			if (state != 0) {
				vc.addElement(item);
			}
	    }
		return vc;
	}
	
	public static void updateThumbnail() {
		// Tools.debugPrintln("请更新目缩略图");
	}

	public static void updateExp() {
		Tools.debugPrintln("请更新经验条");
	}

	public static void updateTarget() {
		// Tools.debugPrintln("请更新目标角色");
	}

	public static void updataCasting(boolean b) {

	}

	private static String m_castingMsg = null;

	public static void updataCastingDescp(boolean b, String content) {
		if (b)
			m_castingMsg = content;
	}

	private void keyBindingMacro() {
		ActorRole role = GameManager.getInstance().m_role;
		if (role.isAliveStatus()) {
			GameMacro gm = role.m_game_macro[0];
			if (gm != null && !gm.checkMacroNull()) {
				gm.init();
				role.m_macro_index = 0;
				role.m_macro_open = true;
			} else {
				RoleCombatSkill skill = role.getCombatSkill(RoleCombatSkill.ID_DK_PG);
				if (skill != null) {
					if (role.canUseCombatSkill(skill, role.m_targetActor)) {// 冷却中,播放中,法力不足
						role.useCombatSkill(skill);
						role.initAutoAttack();
					}
				}
			}
		}
	}

	private void keyLogicOnNormal() {
		// if
		// (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT))
		// {
		// GameManager.getInstance().m_game_message.sendChongzhi("移动", "30",
		// "11795014150778281", "013830087834508004");
		// }
		if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)) {
			GameManager.getInstance().m_role.stand();
			UIMenu.openMenu(true);
		} else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
			GameManager.getInstance().m_role.stand();
			UIMenu.openMenu(false);
		} else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
			GameManager.getInstance().m_role.stopAutoHangUp();
			final AbstractGameActor m_targetActor = GameManager.getInstance().m_role.m_targetActor;
			if (m_targetActor != null) {
				if (GameManager.getInstance().m_role.checkTargetFriend(m_targetActor)) {
					if (m_targetActor.m_type == ActorRole.ACTOR_TYPE_NPC || m_targetActor.m_type == ActorRole.ACTOR_TYPE_GATHERING) {
						GameManager.getInstance().m_role.stopCasting();
						GameManager.getInstance().m_role.stopCastingDescription();
						GameManager.getInstance().m_role.keyAnyStopOther();
						GameManager.getInstance().m_game_message.sendNPCList(m_targetActor.m_gameID);
					} else if (m_targetActor.m_type == ActorRole.ACTOR_TYPE_ROLE && m_targetActor.m_gameID != GameManager.getInstance().m_role.m_gameID) {
						final UIPopmenu popmenu = (UIPopmenu) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_POPMENU);
						String[] popmenus = new String[] { "1.密语", "2.交易", "3.查看", "4.加好友", "5.邀请组队", "6.切磋", "7.跟随" };
						popmenu.setPopmenus(popmenus);
						popmenu.addListener(new UIListener() {
							public void actionPerformed() {
								if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT) || AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
									int index = popmenu.getCurrentIndex();
									switch (index) {
									case 0:// 密语
											// UIChatFace.gotoChatSiliao(m_targetActor.m_gameID,m_targetActor.m_name,
											// "");
										UIChatInsert.gotoSiliao(m_targetActor.m_gameID, m_targetActor.m_name);
										break;
									case 1:// 交易
										GameManager.getInstance().m_game_message.sendDealRequest(m_targetActor.m_gameID);
										break;
									case 2:// 查看
										GameManager.getInstance().m_game_message.sendAttInfos(m_targetActor.m_gameID);
										break;
									case 3:// 加好友
										GameManager.getInstance().m_game_message.sendSocialAdd(GameManager.SOCIAL_TYPE_FRIEND, m_targetActor.m_gameID, m_targetActor.m_name);
										break;
									case 4:// 邀请组队
										GameManager.getInstance().m_game_message.sendTeamRequest(GameManager.getInstance().m_role.m_targetActor.m_gameID);
										break;
									case 5:// 切磋
										GameManager.getInstance().m_game_message.sendDuelRequest(m_targetActor.m_gameID);
										GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_A, "已发送请求,等待对方同意!");
//										GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_A, "暂不开放");
										break;
									case 6:// 跟随
										GameManager.getInstance().m_role.followTargetStart(m_targetActor.m_gameID);
										break;

									}
									UIManager.getInstance().removeWindow(popmenu);
								} else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
									UIManager.getInstance().removeWindow(popmenu);
								} else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY1)) {// 0
									UIChatInsert.gotoSiliao(m_targetActor.m_gameID, m_targetActor.m_name);
									UIManager.getInstance().removeWindow(popmenu);
								} else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY2)) {// 1
									GameManager.getInstance().m_game_message.sendDealRequest(m_targetActor.m_gameID);
									UIManager.getInstance().removeWindow(popmenu);
								} else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY3)) {// 2
									GameManager.getInstance().m_game_message.sendAttInfos(m_targetActor.m_gameID);
									UIManager.getInstance().removeWindow(popmenu);
								} else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY4)) {// 3
									GameManager.getInstance().m_game_message.sendSocialAdd(GameManager.SOCIAL_TYPE_FRIEND, m_targetActor.m_gameID, m_targetActor.m_name);
									UIManager.getInstance().removeWindow(popmenu);
								} else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY5)) {// 4
									GameManager.getInstance().m_game_message.sendTeamRequest(GameManager.getInstance().m_role.m_targetActor.m_gameID);
									UIManager.getInstance().removeWindow(popmenu);
								} else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY6)) {// 5
									UIManager.getInstance().removeWindow(popmenu);
								} else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY8)) {// 7
									GameManager.getInstance().m_role.followTargetStart(m_targetActor.m_gameID);
									UIManager.getInstance().removeWindow(popmenu);
								} else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY9)) {// 8
									UIManager.getInstance().removeWindow(popmenu);
								}
							}
						});
					}
				} else {
					keyBindingMacro();				
				}
			}
		} else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY0)) {// 咒符
		// if (s_spell_type != 0 && s_spell_type != -1) {//
		// 如果设置没开启，或者这打开或关闭过程中，不响应操作
		// byte s = s_spell_switch == (byte) 0 ? (byte) 1 : (byte) 0;
		// s_spell_type = -1;
		// GameManager.getInstance().m_game_message.sendControlSpell(s);
		// }
			if (s_spell_type != -1) {// 如果设置没开启，或者这打开或关闭过程中，不响应操作
				byte value = s_spell_switch == (byte) 0 ? (byte) 1 : (byte) 0;
				switch(value){
					case 0://关
						GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_A, "关闭符咒功能！");
						break;
					case 1://1开
						GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_A, "开启符咒功能！");
						break;
				}
				s_spell_switch = value;
				s_spell_type = -1;
				GameManager.getInstance().m_game_message.sendControlSpell(s_spell_switch);
			}
			// s_spell_switch = s_spell_switch == (byte)0?(byte)1:(byte)0;
			// s_spell_type = -1;
		} else {
			GameManager.getInstance().m_role.keyDir();
		}
		logicZhouFu();
		logicGiftTime();
//		logicShowData();
		((GameScene) GameManager.getInstance().m_scene).m_controlledActor.keyShortcut();

	}

	protected void keyLogic() {
		switch (m_state) {
		case STATE_EQUIP:
			if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
				setWindowStatus(STATE_NORMAL);
				m_yindaos = null;
				UIMenu.gotoTeachEquip();
			}
			break;
		case STATE_LEARN_SKILL:
			if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
				setWindowStatus(STATE_NORMAL);
				m_yindaos = null;
				UIMenu.gotoTeachLearnSkill();
			}
			break;
		case STATE_SET_SHORTCUT:
			if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
				setWindowStatus(STATE_NORMAL);
				m_yindaos = null;
				UIMenu.gotoTeachSetShortcut();
			}
			break;
		case STATE_TASK:
			if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
				setWindowStatus(STATE_NORMAL);
				m_yindaos = null;
				UIMenu.gotoTeachTask();
			}
			break;
		default:
			keyLogicOnNormal();
			break;
		}
	}

	/** 符咒面板 */
	private Image m_img_spell, m_img_spell_huoyan;	
	/** 头像大面板 头像小面板 */
	private Image m_img_head_panel, m_img_head_panel2;
	// private int m_img_head_panel_h, m_img_head_panel2_h;
	private Image m_img_shortcut_rect, m_img_shortcut_rect2, m_img_shortcut_decorate, m_img_shortcut_arrow1, m_img_shortcut_arrow2;
	private Image m_img_Leader;
	// 精力值
	private Image m_img_VimString, m_img_VimFrame, m_img_xiegang;

	/** 头像面板坐标 */
	private final int HEAD_PANEL_SELF_X = 8;
	private final int HEAD_PANEL_SELF_Y = 8;
	private final int HEAD_PANEL_W = 68;
	private final int HEAD_PANEL_H = 23;
	private final int HEAD_PANEL_TARGET_X = 170;
	private final int HEAD_PANEL_TARGET_Y = 8;

	private final int HEAD_ICON_OFFSETX = 10;
	private final int HEAD_ICON_OFFSETY = 20;

	private final int HEAD_HP_OFFSETX = 29;
	private final int HEAD_HP_OFFSETY = 4;
	private final int HEAD_MP_OFFSETX = 29;
	private final int HEAD_MP_OFFSETY = 9;
	private final int HEAD_HP_W = 29;
	private final int HEAD_MP_W = 29;
	private final int HEAD_HP_H = 3;
	private final int HEAD_MP_H = 3;
	private final int HEAD_MP_JK_W = 2; // 剑客每格剑气的宽度

	private final int HEAD_LVL_SELF_OFFSETX = 37;
	private final int HEAD_LVL_TARGET_OFFSETX = 24;
	private final int HEAD_LVL_OFFSETY = 15;
	private final int HEAD_LVL_NUM_W = 5;
	private final int HEAD_LVL_NUM_H = 7;

	// 施法条
	private final int X_CASTING_BAR = (AbstractGameScreen.SCREEN_WIDTH >> 1) - 37;
	private final int Y_CASTING_BAR = AbstractGameScreen.SCREEN_HEIGHT / 3 * 2;
	/*** 队友头像坐标 */
	private final int HEAD_PANEL2_OTHER_X = 2;
	private final int HEAD_PANEL2_OTHER_Y = 57;
	private final int HEAD_PANEL2_W = 20;
	private final int HEAD_PANEL2_H = 20;
	private final int OTHER_HEAD_JIANJU = 10;

	// 缩略图
	private final int X_THUMBNAIL_MAP = AbstractGameScreen.SCREEN_WIDTH - 66;
	private final int Y_THUMBNAIL_MAP = 0;
	
	private final int X_ALERT = X_THUMBNAIL_MAP - 5 ;
	private final int Y_MAIL = Y_THUMBNAIL_MAP + 30 ;
	private final int Y_FIX = Y_MAIL + UIManager.IMAGE_MAIL_UNREAD.getHeight() + 5 ;
	private final int Y_FIGHT= Y_FIX + UIManager.IMAGE_FIX.getHeight() + 5 ;

	private final int HEAD_PANEL2_HP_OFFSETX = 22;
	private final int HEAD_PANEL2_HP_OFFSETY = 57;
	private final int HEAD_PANEL2_HP_W = 4;
	private final int HEAD_PANEL2_HP_H = 20;

	private final int HEAD_LVL_OTHER_OFFSETX = 32;
	private final int HEAD_LVL_OTHER_OFFSETY = 13;
	private final int HEAD_LVL_OTHER_NUM_W = 4;
	private final int HEAD_LVL_OTHER_NUM_H = 67;
	/** Buf相关 */
	private final int BUFFER_Y = HEAD_PANEL_SELF_Y + HEAD_PANEL_H + 1;

	/** 快捷栏相关 */
	private final int SHORTCUT_RECT_W = 22;
	private final int SHORTCUT_RECT_H = 22;
	private final int SHORTCUT_RECT_X = (AbstractGameScreen.SCREEN_WIDTH - (SHORTCUT_RECT_W * 9)) >> 1;// 21
	private final int SHORTCUT_RECT_Y = AbstractGameScreen.SCREEN_HEIGHT - SHORTCUT_RECT_H;
	// private final int SHORTCUT_NUM_W = 5;
//	private final int SHORTCUT_NUM_H = 7;
	// 经验条
	private final int EXPERIENCE_RECT_X = SHORTCUT_RECT_X;
	private final int EXPERIENCE_RECT_W = AbstractGameScreen.SCREEN_WIDTH - (EXPERIENCE_RECT_X << 1);
	private final int EXPERIENCE_RECT_H = 3;
	private final int EXPERIENCE_RECT_Y = AbstractGameScreen.SCREEN_HEIGHT - SHORTCUT_RECT_H - EXPERIENCE_RECT_H;

}
